/*
 * @Author: funlee
 * @Email: i@funlee.cn
 * @Date: 2018-06-15 14:00:45
 * @Description: ramda-object 
 */
import * as _ from 'ramda';

const log = console.log.bind(this);

function Person(name, job) {
  this.name = name;
  this.job = job;
}

Person.prototype.age = 26;

const p = new Person('funlee', 'fe');

log(_.has('name')(p)) // true
log(_.has('job', p)) // true

log(_.has('age', p)) // false
log(_.hasIn('age', p)) // true

log(_.propEq('name', 'funlee')(p)) // true
log(_.propEq('name', 'funlee2', p)) // false
log(_.propEq('age', 26, p)) // true

log(_.whereEq({ 'name': 'funlee' }, p)) // true
log(_.whereEq({ name: 'funlee', job: 'fe', age: 26 }, p)) // true
log(_.whereEq({ name: 'funlee', job: 'feee', age: 26 }, p)) // false

const pred = _.where({
  name: _.equals('funlee'), // name === 'funlee'
  age: _.gt(_.__, 10) // age > 10
})(p)
log(pred)

log('---------------------------')

const tobj = { a: 123, b: 456, c: 789, d: 'AAA', e: 'BBB', f: 'CCC' }
log(_.omit(['d', 'e', 'f'])(tobj))

log(_.filter(value => typeof value === 'string')(tobj))
log(_.reject(value => typeof value === 'string')(tobj))

log('---------------------------')

log(_.dissoc(['a', 'b'])(tobj))
log(_.assoc('a', 'be changed')(tobj))
log(_.partition(value => typeof value === 'string')(tobj))
log(_.pick(['a', 'f'])(tobj))
log(_.pickAll(['a', 'name', 'age'])(tobj))
log(_.pickBy((value, key) => key === 'a' || value % 2 === 0)(tobj))
log(_.keys(p))
log(_.keysIn(p)) // 包含原型上继承的属性
log(_.values(p))
log(_.valuesIn(p))
const sobj = { a: 'AAA', b: 'BBB', c: 'AAA' }
log(_.invertObj(sobj))
log(_.invert(sobj))

log('---------------------------')

log(_.gt(10)(_.prop('a')(tobj)))
log(_.map(value => value + 'be chenged')(tobj))

const testObj = { x: 'AAA', y: 'BBB', z: 'CCC' };
log(_.mapObjIndexed((value, key, obj) => `${key}'s value is ${value}`)(testObj))
log(_.merge(tobj)({a: 'ppp'}))